from flask import Flask, session, app
from datetime import timedelta

# session是给予字典实现的，所以可以调用get，pop来实现添加和删除
# session必须要经过加密，所以必须设置app.secret_key
# session的有效时间必须这样设置

session.permanent = True

app.permanent_session_lifetime = timedelta(seconds=4)

App = Flask(__name__)
App.secret_key = "sad32%@&@skdjwdjd"

@App.route("/")
def index():
    return session.get("username") if session.get("username") else "Not Exist"

@App.route("/name/<name>")
def user(name):
    session["username"] = name
    return "Success"



if __name__ == "__main__":
    app.run(debug=True)